﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Meqs.Entity;
using Meqs.Logic.Interface;
using System.Collections.Generic;

public partial class Situation_CreateSituationExam : System.Web.UI.Page
{
    /// <summary>
    /// 局级考试的创建界面
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitYearAndTerm();
            List<GlobalCauseInfo> list = new List<GlobalCauseInfo>();
            list.Add(new GlobalCauseInfo());
            repeatSubject.DataSource = list;
            repeatSubject.DataBind();
        }

    }

    public string GetTD()
    {
        int index = 5;
        string s = "";
        IGlobalCauseInfoLogic subjectLogic = Container<IGlobalCauseInfoLogic>.Instance;
        Hashtable table = new Hashtable();
        table.Add("IsEffect", 1);
        List<GlobalCauseInfo> list = (List<GlobalCauseInfo>)subjectLogic.FindAll(table);
        foreach (GlobalCauseInfo item in list)
        {
            if (index % 5 == 0)
                s += "<tr>";
            s += "<td style='border:0px solid #ffffff; height:24px;line-height:24px;text-align:left;word-wrap:none;word-break:keep-all;overflow:hidden'>"
                + "<NOBR><input type='checkbox' value=" + item.RID + " />" + item.CauseName + "</td></NOBR>";
            if (index % 5 == 4)
                s += "</tr>";
            index++;
        }
        
        s+= "</tr>";
        return s;
    }

    public int currSchoolYear = 0, currTerm = 0;
    private void InitYearAndTerm()
    {
        //if (CommonScore.SelectSohoolInfo() != null)
        //{
        //    currSchoolYear = CommonScore.SelectSohoolInfo().SchoolYear;
        //    currTerm = CommonScore.SelectSohoolInfo().SchoolTerm;
        //}
        IGlobalTermInfoLogic globalTermInfoLogic = Container<IGlobalTermInfoLogic>.Instance;
        List<GlobalTermInfo> globalTermInfoList = (List<GlobalTermInfo>)globalTermInfoLogic.FindAll();
        if (globalTermInfoList.Count == 0)
            return;

        currSchoolYear = globalTermInfoList[0].GlobalYear;
        currTerm = globalTermInfoList[0].GlobalTerm;
    }


    /// <summary>
    ///  创建局级考试
    /// </summary>
    /// <param name="exam"></param>
    /// <param name="listSubjectId"></param>
    /// <returns></returns>
    [System.Web.Services.WebMethod]
    public static int CreateEduExam(ExamsEducation exam, List<string> listSubjectId)
    {
        IExamsEducationLogic eduExamLogic = Container<IExamsEducationLogic>.Instance;
        List<CauseInfo> list = new List<CauseInfo>();
        string subjIds = "(0";
        foreach (string id in listSubjectId)
        {
            CauseInfo causeInfo = new CauseInfo();
            causeInfo.RID = Convert.ToInt32(id);
            subjIds += "," + id;
            list.Add(causeInfo);
        }
        subjIds += ")";

        exam.AreaID = CommonScore.GetAreaID;

        int n = eduExamLogic.InsertEduExam(exam, list);
        string [] keys= Reports.GetExamTypes(1,exam.Grade);
        foreach (string key in keys)
        {
            IExamSettings ies = Reports.QueryExamSetting(1,key);
            if(ies!=null)
            {
                ies.CreatExamSettingParamer(exam.Grade, exam.ClassType, n, null, subjIds);
            }
        }
        return n;
    }
    
}
